import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

/* 先把VueRouter原型对象的push,先保存一份 */
let originPush=VueRouter.prototype.push;
let originReplace = VueRouter.prototype.replace
//重写push|replace
/* 第一个参数：告诉原来的push方法，往哪里跳转 */

//重写push
VueRouter.prototype.push=function(location,resolve,reject){
  if(resolve&&reject){
    //call||apply区别
    //相同点，都可以调用函数一次，都可以篡改函数的上下文一次
    //不同点：call与apply传递参数：call传递参数用逗号隔开，apply方法执行。传递数组
    //this还是用该上下文调用，也就是vuerouter的实例，后面跟参数指定跳的位置，以及成功失败的回调
    originPush.call(this,location,resolve,reject)
  }else{
    originPush.call(this,location,()=>{},()=>{})
  }
}


//重写replace
VueRouter.prototype.replace = function(location,resolve,reject){
  if(resolve&&reject){
    originReplace.call(this,location,resolve,reject)
  }else{
    originReplace.call(this,location,()=>{},()=>{})
  }
}

const routes = [
  {
    path: "/",
    redirect: "Login",
  },
  {
    path: "/Index",
    name: "Index",
    component: () => import("../views/Index.vue"),
    children: [
      {
        path: "/Menu",
        name: "Menu",
        component: () => import("../views/Menu.vue"),
      },
      {
        path: "/Role",
        name: "Role",
        component: () => import("../views/Role.vue"),
      },
      {
        path: "/User",
        name: "User",
        component: () => import("../pages/User.vue"),
      },
      {
        path: "/log/OperLog",
        name: "OperLog",
        component: () => import("../views/OperLog.vue"),
      },
      {
        path: "/DictType",
        name: "DictType",
        component: () => import("../pages/DictType.vue"),
      },
      {
        path: "/DictData",
        name: "DictData",
        component: () => import("../pages/DictData.vue"),
      },
      {
        path: "/CarType",
        name: "CarType",
        component: () => import("../views/CarType.vue"),
      },
      {
        path: "/CarComment",
        name: "CarComment",
        component: () => import("../pages/CarComment.vue"),
      },
      {
        path: '/log/loginLog',
        name: 'LoginLog',
        component: () => import('../views/LoginLog.vue')
      },
      {
        path: "/echarts/money-show",
        name: "MoneyShow",
        component: () => import("../views/StatisticsMoney.vue"),
      },
      {
        path: "/Brand",
        name: "Brand",
        component: () => import("../views/Brand.vue"),
      },
      {
        path: "/TypeConfig",
        name: "TypeConfig",
        component: () => import("../views/CarTypeConfigDetails.vue"),
      },
      {
        path: '/echarts/oper-log-show',
        name: 'OperLogShow',
        component: () => import('../views/StatisticsOper.vue')
      },
      {
        path: '/echarts/login-log-show',
        name: 'LoginLogShow',
        component: () => import('../views/StatisticsLogin.vue')
      },
      {
        path: '/mks/customer_issues',
        name: 'CustomerIssues',
        component: () => import('../views/CustomerIssues.vue')
      },
      {
        path: '/Advertise',
        name: 'Advertise',
        component: () => import('../views/Advertise.vue')
      },
      {
        path: '/AdvertisePosition',
        name: 'AdvertisePosition',
        component: () => import('../views/AdvertisePosition.vue')
      },
      {
        path: '/Coupon',
        name: 'Coupon',
        component: () => import('../pages/Coupon.vue')
      },
      {
        path: '/CouponHistory',
        name: 'CouponHistory',
        component: () => import('../pages/CouponHistory.vue')
      },
      {
        path: "/Company",
        name: "Company",
        component: () => import("../views/Company.vue"),
      },
      {
        path: "/MaintainRecord",
        name: "MaintainRecord",
        component: () => import("../views/MaintainRecord.vue"),
      },
      {
        path: "/MaintainShop",
        name: "MaintainShop",
        component: () => import("../views/MaintainShopController.vue"),
      },
      {
        path: "/Shop",
        name: "Shop",
        component: () => import("../views/Shop.vue"),
      },
      {
        path: "/Car",
        name: "Car",
        component: () => import("../views/Car.vue"),
      },
      {
        path: '/Member',
        name: 'Member',
        component: () => import('../pages/Member.vue')
      },
      {
        path: '/MemberLevel',
        name: 'MemberLevel',
        component: () => import('../pages/MemberLevel.vue')
      },
      {
        path: '/IntegrationHistory',
        name: 'IntegrationHistory',
        component: () => import('../pages/IntegrationHistory.vue')
      },
      {
        path: '/Order',
        name: 'Order',
        component: () => import('../pages/Order.vue')
      }
    ]
  },
  {
    path: "/Login",
        name: "Login",
      component: () => import("../views/Login.vue"),
  },
]

const router = new VueRouter({
  routes
})

export default router
